package com.dingreading.cloud.admin.util;


import com.dingreading.cloud.admin.entity.HeadStaff;
import com.dingreading.cloud.common.util.KitUtil;

/**
 * 密码通用工具
 *
 * @author xiaofan
 */
public class PasswordUtil {

    /**
     * 设置默认随机密码
     */
    public static void createPassword(HeadStaff entity, String password) {
        //新建设置密码
        //设置随机秘钥
        String salt = KitUtil.getRandomStr(4);
        entity.setPwdSalt(salt);
        //密码加密
        String encodePwd = RC4Util.encry_RC4_string(password, salt);
        entity.setEncodedPwd(encodePwd);
    }

    /**
     * 总部员工设置新密码
     */
    public static void resetPassword(HeadStaff entity, String password) {
        //新建设置密码
        //设置随机秘钥
        String salt = KitUtil.getRandomStr(4);
        entity.setPwdSalt(salt);
        //密码加密
        String encodePwd = RC4Util.encry_RC4_string(password, salt);
        entity.setEncodedPwd(encodePwd);
    }


    public static String decryptionPassword(String encodedPwd, String pwdSalt) {
        String decryPwd = RC4Util.decry_RC4(encodedPwd, pwdSalt);
        return decryPwd;
    }


    public static void main(String[] args) {
        String salt = KitUtil.getRandomStr(8);
        System.out.println("salt = " + salt);
        //密码加密
        String encodePwd = RC4Util.encry_RC4_string("123456", salt);
        System.out.println("encodePwd = " + encodePwd);
    }

}